package com.jwthhealth_pub.old.diet.view;

import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.common.view.TitleLayout;
import com.jwthhealth_pub.old.diet.view.adapter.DietAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 饮食调养
 * Created by Administrator on 2016/12/26.
 */
public class DietActivity extends FragmentActivity {
    @BindView(R.id.tl_diet)
    TabLayout tlDiet;
    @BindView(R.id.vp_diet)
    ViewPager vpDiet;
    @BindView(R.id.sign_topbar)
    TitleLayout signTopbar;
    private DietAdapter dietAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_diet);
        ButterKnife.bind(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }

        initNavigation();
        initClicke();
    }

    private void initNavigation() {
        dietAdapter = new DietAdapter(getSupportFragmentManager(), DietActivity.this, tlDiet);
        vpDiet.setAdapter(dietAdapter);

        tlDiet.setupWithViewPager(vpDiet);
        tlDiet.setTabMode(TabLayout.MODE_FIXED);
        tlDiet.setSelectedTabIndicatorColor(getResources().getColor(R.color.primarycolor));
        for (int i = 0; i < tlDiet.getTabCount(); i++) {
            TabLayout.Tab tab = tlDiet.getTabAt(i);
            View tabView = dietAdapter.getTabView(i);
            if (tabView != null) {
                tab.setCustomView(tabView);
            }
        }

        tlDiet.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                dietAdapter.changeState(true, tab);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                dietAdapter.changeState(false, tab);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
            }
        });
    }

    private void initClicke() {
        signTopbar.setOnTitleLayoutListener(new TitleLayout.TitleLayoutListener() {
            @Override
            public void leftclick() {
                finish();
            }

            @Override
            public void leftTextClick() {

            }

            @Override
            public void rightclick() {

            }

            @Override
            public void rightTextClick() {

            }
        });
    }


}
